/*
 * Ejercicio realizado por Francisco Gonzalez-Armijo Riádigos
 * para la prueba de seleccion de http://www.nomasystems.es
 */

package es.kuassivi.android.cd.tests;

import android.content.Intent;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.widget.ListView;
import es.kuassivi.android.cd.MainActivity;
import es.kuassivi.android.cd.R;
import es.kuassivi.android.cd.business.CustomCompanyREST;

/**
 * Test para el modelo CompanyREST
 * Para ejecutar todos los test ver {@link AllTests}
 * 
 * @author kuassivi <a href="mailto:kuassivi@gmail.com">kuassivi@gmail.com</a>
 * @since 0.1
 */
public class CustomCompanyRESTTest extends ActivityUnitTestCase<MainActivity> 
{

    private Intent mStartIntent;
    
    public ListView companiesList;
    
    
    public CustomCompanyRESTTest() 
    {
        super(MainActivity.class);
    }

    @Override
    protected void setUp() throws Exception 
    {
        super.setUp();
        mStartIntent = new Intent(Intent.ACTION_MAIN);
    }
    
	/**
	 * Comprobamos que el metodo carga los datos en la vista
	 */
	@SmallTest
	public void testLoadCompanies()
	{
		startActivity(mStartIntent, null, null);
		
		getActivity().runOnUiThread(new Runnable() {
	  		  @Override
	  		  public void run() {
	  			  	new CustomCompanyREST(getActivity()).loadCompanies();
	  			
		  			companiesList = (ListView) getActivity().findViewById(R.id.companyList);
	  		  }
	  		});
		
	  	getInstrumentation().waitForIdleSync();
	  	
	  	int numAdapters = companiesList.getAdapter().getCount();
	  	
	  	assertEquals(2, numAdapters);
	}
	
}
